/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import DAL.ClassDAL;
import DAL.ExaminationDAL;
import Entities.TblMarkUpload;
import Entities.TblStaff;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author CuongNV
 */
@ManagedBean
@SessionScoped
public class ApprovalMarkManagedBean {

    /** Creates a new instance of ApprovalMarkManagedBean */
    TblStaff faculty;
    List<TblMarkUpload> listMarkUpload;
    int examId;
    int classId;

    public int getClassId() {
        return classId;
    }

    public void setClassId(int classId) {
        this.classId = classId;
    }

    public int getExamId() {
        return examId;
    }

    public void setExamId(int examId) {
        this.examId = examId;
    }

    public ApprovalMarkManagedBean() {
        faculty = getStaff();        
    }

    public TblStaff getStaff(){

        TblStaff staff = new TblStaff();
        staff = (TblStaff)getSession("staff");

        return staff;
    }

    public static void setSession(String key, Object value) {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        session.setAttribute(key, value);
    }

    public static Object getSession(String key) {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        return session.getAttribute(key);
    }

    public TblStaff getFaculty() {
        return faculty;
    }

    public void setFaculty(TblStaff faculty) {
        this.faculty = faculty;
    }

    public List<TblMarkUpload> layListExamAndClassByFacultyId(int facultyId){
        listMarkUpload = new DAL.MarkUploadDAL().getExamEndClassByFacultyId(facultyId);
        return listMarkUpload;
    }

    public List<TblMarkUpload> getListMarkUpload() {
        return new DAL.MarkUploadDAL().getExamEndClassByFacultyId(faculty.getStaffId());
    }

    public void setListMarkUpload(List<TblMarkUpload> listMarkUpload) {
        this.listMarkUpload = listMarkUpload;
    }

    public String layExamNameByExamId(int examId){
        String examName = new ExaminationDAL().getById(examId).getExamName();
        return examName;
    }

    public String layClassNameByClassId(int classId){
        String className = new ClassDAL().getById(classId).getClassName();
        return className;
    }
}
